package com.gzck.gzck_verson2.globalExceptionHandler;

import cn.dev33.satoken.util.SaResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.UncheckedIOException;

/**
 *  全局异常拦截
 */
@RestControllerAdvice
@Component
public class GlobalExceptionHandler {
    // 全局异常拦截 
    @ExceptionHandler
    public SaResult handlerException(Exception e) {
        e.printStackTrace();
        return SaResult.error(e.getMessage());
    }


    /**
     * 拦截住图片上传时删除缓存失败的异常
     * @param e
     * @return
     */
    @ExceptionHandler(UncheckedIOException.class)
    public ResponseEntity<String> handleUncheckedIOException(UncheckedIOException e) {
        e.printStackTrace();
        return ResponseEntity.status(HttpStatus.OK)
                .body("UncheckedIOException handled: " + e.getMessage());
    }
}
